//package com.intexhcomkda.kda.helper;
//
//import android.Manifest;
//import android.content.Context;
//import android.content.DialogInterface;
//import android.support.v7.app.AlertDialog;
//import android.text.TextUtils;
//
//import com.amap.api.location.AMapLocationClient;
//import com.amap.api.location.AMapLocationClientOption;
//import com.intexhcomkda.kda.R;
//import com.intexhcomkda.kda.base.MainApplication;
//import com.intexhcomkda.kda.utils.LogUtil;
//import com.intexhcomkda.kda.utils.ToastUtil;
//import com.yanzhenjie.permission.AndPermission;
//import com.yanzhenjie.permission.Permission;
//import com.yanzhenjie.permission.Setting;
//
//import java.util.List;
//
//
//
//public enum LocationHelper {
//    INSTANCE;
//    public void getLocation(Context context,OnLocationCalBack calBack){
//
//
//        AndPermission.with(context)
//                .runtime()
//                .permission(Manifest.permission.ACCESS_FINE_LOCATION,Manifest.permission.ACCESS_COARSE_LOCATION)
//                .onGranted(permissions -> {
//                    //权限申请成功过
//                    final int[] errorCount = {0};
//                    AMapLocationClient mLocationClient = new AMapLocationClient(MainApplication.getAppContext());
//                    mLocationClient.setLocationListener(aMapLocation -> {
//                        if (aMapLocation != null) {
//                            if (aMapLocation.getErrorCode() == 0) {
//                                //定位成功后停止定位
//                                mLocationClient.stopLocation();
//                                LogUtil.e("frank","定位成功："+aMapLocation.getLatitude()+"-"+aMapLocation.getLongitude()+"-"+
//                                        aMapLocation.getProvince()+"-"+aMapLocation.getCity()+"-"+aMapLocation.getDistrict()+"-"+aMapLocation.getAddress());
//                                calBack.onLocationSuccess(aMapLocation.getLatitude(),aMapLocation.getLongitude(),
//                                        aMapLocation.getProvince(),aMapLocation.getCity(),aMapLocation.getDistrict(),aMapLocation.getAddress());
//                            }else {
//                                errorCount[0]++;
//                                if(errorCount[0]>5){
//                                    mLocationClient.stopLocation();
//                                    calBack.onLocationFail("高德定位失败,"+aMapLocation.getErrorCode()+"-"+aMapLocation.getErrorInfo());
//                                }
//                                //定位失败时，可通过ErrCode（错误码）信息来确定失败的原因，errInfo是错误信息，详见错误码表。
//                                LogUtil.e("frank","高德定位失败, ErrCode:"
//                                        + aMapLocation.getErrorCode() + ", errInfo:"
//                                        + aMapLocation.getErrorInfo());
//                            }
//                        }
//                    });
//                    AMapLocationClientOption option = new AMapLocationClientOption();
//                    option.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);
//                    option.setOnceLocation(false);
//                    option.setInterval(1000);
//                    option.setNeedAddress(true);
//                    //给定位客户端对象设置定位参数
//                    mLocationClient.setLocationOption(option);
//                    //启动定位
//                    mLocationClient.startLocation();
//                })
//                .onDenied(permissions -> {
//                    ToastUtil.showToast(context,"权限申请失败");
//                    if (AndPermission.hasAlwaysDeniedPermission(context, permissions)) {
//                        showSettingDialog(context, permissions);
//                    }
//                })
//                .start();
//    }
//
//    public interface OnLocationCalBack{
//        void onLocationSuccess(double lat, double lng,String province,String city,String district, String msg);
//        void onLocationFail(String msg);    //定位失败时会继续发起定位 间隔1秒，失败多次此方法执行多次
//    }
//
//
//    /**
//     * Display setting dialog.
//     //用户始终禁止权限 弹出设置提示框
//     <string name="message_permission_always_failed" >请到应用设置同意权限申请:\n\n%1$s</string>
//     */
//    public void showSettingDialog(Context context, final List<String> permissions) {
//        List<String> permissionNames = Permission.transformText(context, permissions);
//        String message = context.getString(R.string.message_permission_always_failed, TextUtils.join("\n", permissionNames));
//
//        new AlertDialog.Builder(context)
//                .setCancelable(false)
//                .setTitle("提示")
//                .setMessage(message)
//                .setPositiveButton(R.string.setting, new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialog, int which) {
//                        setPermission(context);
//                    }
//                })
//                .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
//                    @Override
//                    public void onClick(DialogInterface dialog, int which) {
//                    }
//                })
//                .show();
//    }
//
//    /**
//     * Set permissions.
//     */
//    private void setPermission(Context context) {
//        AndPermission.with(context)
//                .runtime()
//                .setting()
//                .onComeback(new Setting.Action() {
//                    @Override
//                    public void onAction() {
//                        LogUtil.e("frank","从设置页返回");
//                    }
//                })
//                .start();
//    }
//
//}
